<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Cases extends Model
{
    protected $table = 'sf_cases';
    protected $primaryKey = 'id';

    public function classify(){
        return $this->hasOne('App\Classify','id','classify_id');
    }
    public static function getRecommend(){
        return self::with('classify')->where('status', '=', 1)->orderBy('created_at','desc')->take(9)->get();
    }

    public static function pageCase($classify_id,$num){
        if($classify_id == 0){
            return  self::orderBy('created_at', 'desc')->paginate($num);
        }
        return  self::whereRaw("`classify_id` = {$classify_id}")->orderBy('created_at', 'desc')->paginate($num);
    }

    public static function getCaseInfo($case_id){
        return self::with('classify')->find($case_id);
    }

}
